const express = require("express");
const bodyParser = require("body-parser");
const fs = require("fs");
const static = express.static;
const { expressjwt } = require("express-jwt");

let app = express();
app.use(expressjwt({secret:"mytoken",algorithms:['HS256']}).unless({path:[/\/checkuser/,/\/checkusername/,/\.jpg$/,/\.png$/] }))
app.use(static("./static"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended:false
}))
// 如果没有 static 目录 那么自动创建一个static
if(!fs.existsSync("./static")){
    fs.mkdirSync("./static");
}

// 登录的路由 ；一级路由
const loginRouter = require("./routers/loginRouter");
app.use(loginRouter);

// 用户的路由地址 ： 二级路由
const userRouter = require("./routers/usersRouter");
const advRouter = require("./routers/advRouter")

app.use("/admin",userRouter);
app.use("/admin",advRouter);

app.listen(8989);
